from page.net_project_page import NetProjectPage
from common.page import XPATH
from time import sleep
from selenium.common.exceptions import NoSuchElementException


class AbilityPage(NetProjectPage):

    def choose_answer(self):
        answer_list = ["很符合", "符合", "一般", "不符合", "很不符合"]
        for i in range(len(answer_list)-1):
            try:
                self.get_frame_center_and_click_limit((
                    XPATH,
                    "//XCUIElementTypeStaticText[@name='%s']"
                    "/../following-sibling::XCUIElementTypeOther[@value='0']" % answer_list[i]),
                    limit=70
                )
            except NoSuchElementException:
                continue
            else:
                print(answer_list[i+1])
                break

    def test_h5(self):
        self.enter_project("APP测试微能力测评")
        sleep(2)
        self.find_button('去测评').click()
        sleep(3)
        for i in range(15):
            self.choose_answer()
            self.swipe_dr("up")
        self.find_static_text('确认提交').click()


if __name__ == '__main__':
    test = AbilityPage()
    test.test_h5()
